<?php
/**
 * ICECAST - A Joomla internet radio statistic module
 * @version 1.0.9
 * @package mod_icecast.zip
 * @copyright (C) 2009 - 2010 by Gronpipmaster and sli
 */
defined('_JEXEC') or die('Direct Access to this location is not allowed.');

class ModHelperIceCast
{
	public static function getParams(&$params)
	{
		$result = new StdClass;
		if (ini_get('display_errors') == 1) ini_set('display_errors', 0);
		$fp = fsockopen($params->get('host'), $params->get('port'), $errno, $errstr, 30); //open connection
		if(!$fp) {
			$result->status = 2;

		} else { //if connection
			$serverpoint = $params->get('point');
			fputs($fp,"GET /status2.xsl?mount=/$serverpoint HTTP/1.0\r\nUser-Agent: Icecast2 XSL Parser (Mozilla Compatible)\r\n\r\n"); //get status2.xsl
			while(!feof($fp)) {
				$page .= fgets($fp, 1000);
			}
			fclose($fp); //close connection
			$page = ereg_replace('.*<pre>(.*)</pre>', '\1', $page); //Получаем данные

			$numbers = explode(",",$page); //начала проверки пунктов

			if (strlen($numbers[11])<2) {
				$result->status = 1;

			} else {
				$result->status = 0;

				$mount = $numbers[11];
				$listeners = $numbers[14];
				$cur_song = $numbers[16];
				$listfake = $listeners + $fake;

				$result->mount     = $numbers[11];
				$result->listeners = $numbers[14];
				$result->cur_song  = $numbers[16];
				$result->listfake  = $result->listeners + $params->get('fake');
			}
		}
		return $result;
	}
}
?>
